<?php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use JPush\Model as M;
use JPush\JPushClient;

class JpushServiceProvider extends ServiceProvider
{

	protected $defer = true;

	/**
	 * Register the application services.
	 *
	 * @return void
	 */
	public function register()
	{
		$this->app->bind('jpush', function ($app)
		{
			$app_key = $app->config->get('jpush.app_key');
			$master_secret = $app->config->get('jpush.master_secret');
			return new JPushClient($app_key, $master_secret);
		});

		$this->app->bind('jpush.push', function ($app)
		{
            $apns_production = env('APP_DEBUG')? false : true;
			return $app['jpush']->push()
				->setPlatform(M\all)
                ->setOptions(M\options(time(),null,null,$apns_production));
		});
	}

	public function provides()
	{
		return [
			'jpush',
			'jpush.push'
		];
	}
}
